<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//小程序列表
	$params=array('uniacid'=>$_SESSION['uniacid'],'ali_appid <>'=>'');
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=trim($_RQ['title']);
	}
	$fields=array('id','title','appid','type','version','plugin_name','ali_appid','uptime','api_data');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('core_account_wxapp',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$row){
			$row['api_data']=json_decode($row['api_data'],true);
		}
	}
	$return['statuss']=$statuss;
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('psize'=>$psize,'total'=>$total,'tip'=>'这里显示所有的已经设置了【支付宝appid】的小程序，你可以按需设置小程序的《E签宝模板ID》
		','data'=>'list','edit'=>false,'list'=>array(
			array('type'=>'string','title'=>'小程序id','name'=>'id'),
			array('type'=>'string','title'=>'小程序名称','name'=>'title'),
			array('name'=>'plugin_name','title'=>'所属插件','type'=>'select','options'=>'plugins'),
			array('type'=>'radio','title'=>'小程序类型','name'=>'type','options'=>'types'),
			array('type'=>'string','title'=>'支付宝appid','name'=>'ali_appid'),
			array('type'=>'string','title'=>'E签宝模板ID','name'=>'api_data.esigntpid'),
		),'action'=>array(
			array('type'=>'modal','op'=>'setservice_id','title'=>'设置合同模板ID'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'type'=>'string','title'=>'小程序名称'),
			array('type'=>'select','width'=>13,'title'=>'所属插件','name'=>'plugin_name','options'=>'apps','option_value'=>'name'),
		)
	);
	$return['types']=array(
		'1'=>'DIY小程序',
		'2'=>'插件小程序',
		'7'=>'打包H5小程序',
		'8'=>'多页小程序',
	);
	$return['plugins']=pdo_getall('core_plugins','',array('name','title'),'name');
	$return['plugins']['core']=array('name'=>'core','title'=>'微官网');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='setservice_id'){
	//设置小程序支付参数
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('请先选择要设置的小程序！','error');
		}
		$data=array(
			'api_data'=>ijson_encode($post['api_data']),
		);
		pdo_update('core_account_wxapp',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('设置成功！','','list');
	}else{
		$id=intval($_RQ['id']);
		if(!$id){
			exi('请先选择要设置的小程序！','error','list');
		}
		$item=pdo_get('core_account_wxapp',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('id','title','api_data'));
		$item['api_data']=json_decode($item['api_data'],true);
		$return['item']=$item;
		$return['htmls']=array(
			'type'=>'edit',
			'desc'=>'设置合同模板ID',
			'edit'=>array(
				array('type'=>'copy','name'=>'title','title'=>'小程序名称'),
				array('type'=>'string','title'=>'合同模板ID','name'=>'api_data.esigntpid'),
			),
		);
		exi($return);
	}
}